package com.lock.subscribe.msg;


import java.util.HashMap;
import java.util.Map;

import com.lock.subscribe.constant.ReportDataKey;
import com.lock.subscribe.util.ByteTools;



public class MessageMapParse {
    /**
     * @param messageLength
     * @param message
     * @return
     */
    public static Map<String,Object> parseMessage(Integer messageLength, String message){
    	if(messageLength==0){ return null ;}
        try{
            Map<String,Object> map = new HashMap<>();
            Integer index =0 ;
            while (index<messageLength){
                String flag = message.substring(index,index+=2).toLowerCase();
                String length = message.substring(index,index+=2);
                String data = message.substring(index,index+=Integer.parseInt(length,16)*2);
                if(flag.equals("77")||flag.equals("78")){
                    map.put(ReportDataKey.reportDataKeyMap.get(flag),ByteTools.hexStringToString(data));
                }else if(flag.equals("73")) {
                	map.put(ReportDataKey.reportDataKeyMap.get(flag),data);
                }
                else{
                    map.put(ReportDataKey.reportDataKeyMap.get(flag),Long.valueOf(data,16));
                }
            }
           
            return map;
        }catch (Exception e){
            throw new RuntimeException(e);
        }
    }
}
